import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [{
    path: "/",
    redirect: {
      name: "index",
    },
  },
  {
    path: "/index",
    name: "index",
    component: () =>
      import ( /* webpackChunkName: "about" */ "../views/Home/Index.vue"),
    meta: { title: "博客-首页" },
  },
  {
    path: "/archives",
    name: "archives",
    component: () =>
      import ( /* webpackChunkName: "archives" */ "../views/Archives/Index.vue"),
    meta: { title: "博客-归档页" },
  },
  {
    path: "/categories",
    name: "categories",
    component: () =>
      import (
        /* webpackChunkName: "categories" */
        "../views/Categories/Index.vue"
      ),
    meta: { title: "博客-分类页" },
  },
  {
    path: "/categories/details",
    name: "categoriesDetails",
    component: () =>
      import (
        /* webpackChunkName: "categoriesDetails" */
        "../views/Categories/Details.vue"
      ),
    meta: { title: "博客-分类详情页" },
  },
  {
    path: "/tags",
    name: "tags",
    component: () =>
      import ( /* webpackChunkName: "tags" */ "../views/Tags/Index.vue"),
    meta: { title: "博客-归档页" },
  },
  {
    path: "/tags/details",
    name: "tagsDetails",
    component: () =>
      import ( /* webpackChunkName: "tagsDetails" */ "../views/Tags/Details.vue"),
    meta: { title: "博客-归档详情页" },
  },
  {
    path: "/about",
    name: "about",
    component: () =>
      import ( /* webpackChunkName: "about" */ "../views/About/Index.vue"),
    meta: { title: "博客-关于页" },
  },
  {
    path: "/articles",
    name: "articles",
    component: () =>
      import ( /* webpackChunkName: "articles" */ "../views/Articles/Index.vue"),
    meta: { title: "博客-文章页" },
  },
  {
    path: "/articles/details",
    name: "articlesDetails",
    component: () =>
      import (
        /* webpackChunkName: "articlesDetails" */
        "../views/Articles/Details.vue"
      ),
    meta: { title: "博客-文章详情页" },
  },
  {
    path: "/user",
    name: "user",
    component: () =>
      import (
        /* webpackChunkName: "User" */
        "../views/User/Index.vue"
      ),
    meta: { title: "博客-个人中心页" },
  },
  {
    path: "*",
    name: "notFound",
    component: () =>
      import (
        /* webpackChunkName: "notFound" */
        "../views/User/NotFound.vue"
      ),
    meta: { title: "博客-找不到页面" },
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  next();
  document.title = to.meta.title;
});

export default router;
